package com.example.karenandroiddemo;

import com.example.karenandroiddemo.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

public class WebsiteList extends ListFragment {
	
	
    String[] website = new String[] {
            "CNN",
            "LinkedIn",
            "Google Play",
            "Android Developer"            
    };    
    
    
    int[] logo = new int[]{
    		R.drawable.cnn_logo,
    		R.drawable.linkedin_logo,
    		R.drawable.googleplay_logo,
    		R.drawable.androiddev_logo    			
    };
    
    
    String[] webinfo = new String[]{
    	"News Portal",
    	"Professional Social Networking",
    	"Android Market",
    	"Android Developer Community"    	
    };
    
    
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {	
		
		// Each row in the list stores websitename, webinfo and logo
        List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();        
        
        for(int i=0;i<4;i++){
        	HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("website", "Website : " + website[i]);
            hm.put("webinfo","Web Info : " + webinfo[i]);
            hm.put("logo", Integer.toString(logo[i]) );            
            aList.add(hm);        
        }
        
        // Keys used in Hashmap
        String[] from = { "logo","website","webinfo" };
        
        // Ids of views in listview_layout
        int[] to = { R.id.logo,R.id.website,R.id.webinfo};        
        
        // Instantiating an adapter to store each items
        // R.layout.listview_layout defines the layout of each item
        SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.websitelistview_layout, from, to);       
		
		setListAdapter(adapter);
		
		return super.onCreateView(inflater, container, savedInstanceState);		
	}

}
